/**
 * RequestStatus.java
 * com.aabill.api
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-8-14 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.api;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * ClassName:RequestStatus
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-8-14 上午8:19:44 
 */
public class RequestStatus extends JsonResponse{



	/**
	 * user 1
	 * circle 2
	 * bill 3
	 * friend 4
	 */
	private static final int NO_REQUEST_CODE= -1;					//未返回状态码
	private static final int OK= 0;									//成功
	private static final int AUTH_FAILED= 10001;					//用户认证失败
	private static final int DUPLICATE_REGISTER = 10002;			//重复注册
	private static final int NO_PERMISSION = 10006;					//没权限
	private static final int CIRCLE_NULL = 20011;        	 		//没有circle
	private static final int CIRCLE_MEMBER_DUPLICATE = 20014;       //circle mem重复



	public RequestStatus(JSONObject jsonStr){
		try {
			JSONObject jsonObject = jsonStr.getJSONObject("status");
			request_status = getInt("request_status", jsonObject);
		} catch (JSONException e) {
		}
		setError_msg(bindErrorMsg(request_status));
	}


	int request_status = -1;
	String error_msg = "";


	public int getRequest_status() {
		return request_status;
	}

	public void setRequest_status(int request_status) {
		this.request_status = request_status;
	}
	
	public String getError_msg() {
		return error_msg;
	}

	public void setError_msg(String error_msg) {
		this.error_msg = error_msg;
	}

	/**
	 * 根据错误码，得到错误信息<br>
	 * @method getErrorMsg
	 * @param error_code
	 * @return
	 * @throws 
	 * @since v1.0
	 */
	private String bindErrorMsg(int error_code) {
		switch(error_code){
		case NO_REQUEST_CODE:
			return "NO_REQUEST_CODE";
		case OK:
			return "OK";
		case AUTH_FAILED:
			return "AUTH_FAILED";
		case DUPLICATE_REGISTER:
			return "DUPLICATE_REGISTER";
		case NO_PERMISSION:
			return "NO_PERMISSION";
		case CIRCLE_NULL:
			return "CIRCLE_NULL";
		case CIRCLE_MEMBER_DUPLICATE:
			return "CIRCLE_MEMBER_DUPLICATE";
		default:
			return "I Don't Know What Happend";
		}
	}


	@Override
	public String toString() {
		return "RequestStatus:{ " +
				"request_status = '"+ request_status + "\'" + "," + 
				//				"error_code = '"+ error_code + "\'" + "," +
				"}"; 
	}




}

